package cn.wolfcode.web.controller;

import cn.wolfcode.common.web.Result;
import cn.wolfcode.domain.OperateIntegralVo;
import cn.wolfcode.domain.RefundVo;
import cn.wolfcode.service.IUsableIntegralService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/intergral")
public class IntegralController {

    @Autowired
    private IUsableIntegralService usableIntegralService;

    /**
     * 积分支付
     */
    @PostMapping("/integral/prePay")
    public Result<String> prePay(@RequestBody OperateIntegralVo operateIntegralVo) {
        // 积分支付
        //String tradeNo = usableIntegralService.doPay(operateIntegralVo);
        String tradeNo = usableIntegralService.tryPayment(operateIntegralVo, null);
        return Result.success(tradeNo);
    }

    /**
     * 积分退款
     */
    @PostMapping("/refund")
    Result<Boolean> refund(@RequestBody RefundVo refundVo) {
        boolean res = usableIntegralService.doRefund(refundVo);
        return Result.success(res);
    }

}
